﻿using System;
using System.Linq;
using ProjetoComperio.DataLayer.Entities;
using ProjetoComperio.DataLayer.Infra;

namespace ProjetoComperio.BusinessLogicLayer
{
    public class AcademicCoordinatorBLL : ComperioDataObject
    {
        PersonBLL personBLL;
        public AcademicCoordinatorBLL()
        {
            personBLL = new PersonBLL();
        }

        public void Create(AcademicCoordinator academicCoordinator)
        {
            if (String.IsNullOrEmpty(academicCoordinator.WebPage))
                academicCoordinator.WebPage = "http://www.faetec.rj.gov.br/ist-rio";
            DbContext.People.Add(academicCoordinator);
            DbContext.SaveChanges();

        }

        /// <summary>
        /// This method retrieve an specific AcademicCoordinator by personID
        /// </summary>
        /// <param name="personID"></param>
        /// <returns></returns>
        public IQueryable<AcademicCoordinator> RetrieveAcademicCoordinatorByID(Int32 personID)
        {
            return DbContext.People.OfType<AcademicCoordinator>().Where(academicCoordinator => academicCoordinator.PersonID == personID);

        }

        public IQueryable<AcademicCoordinator> RetrieveAcademicCoordinators()
        {
            return DbContext.People.OfType<AcademicCoordinator>();

        }

        /// <summary>
        /// This method delete an AcademicCoordinator
        /// </summary>
        /// <param name="person"></param>
        public void Delete(AcademicCoordinator academicCoordinator)
        {
            personBLL.Delete(academicCoordinator);

        }

        public AcademicCoordinator RetrieveAcademicPersonByID(int p)
        {
            return DbContext.People.OfType<AcademicCoordinator>().Where(academicCoordinator => academicCoordinator.PersonID == p).FirstOrDefault();
        }
    }
}
